package demo1;

/**
 * Lambda 表达式的演示示例*/

//无返回值
@FunctionalInterface
interface NoParameterNoReturn{
    void test();
}
@FunctionalInterface
interface OneParameterNoReturn{
    void test(int x);
}
@FunctionalInterface
interface MoreParameterNoReturn{
    void test(int x,int y);
}

//有返回值
@FunctionalInterface
interface NoParameter {
    int test();
}
@FunctionalInterface
interface OneParameter {
    int test(int x);
}
@FunctionalInterface
interface MoreParameter {
    int test(int x, int y);
}
public class Test {
    public static void main(String[] args) {
        NoParameter noParameter = () -> 1;
        System.out.println(noParameter.test());

        OneParameter oneParameter = x-> {return x*3;};
        System.out.println(oneParameter.test(3));

        MoreParameter moreParameter = (int x, int y) -> {return x+y;};
        System.out.println(moreParameter.test(3,4));
    }
    public static void main1(String[] args) {
        //创建匿名内部类调用接口中的方法
        NoParameterNoReturn noParameterNoReturn = new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("创建匿名内部类调用接口中的抽象方法");
            }
        };
        noParameterNoReturn.test();
    }

    public static void main2(String[] args) {
        OneParameterNoReturn oneParameterNoReturn =
                x -> System.out.println("使用Lambda表达式调用函数式接口");
        oneParameterNoReturn.test(2);

        MoreParameterNoReturn moreParameterNoReturn =
                (x,y) -> System.out.println("是哟个Lambda表达式调用函数式接口");
    }
}
